package cn.wizzer.app.web.modules.controllers.crown;

import cn.wizzer.app.crown.modules.models.enums.BetsEnum;
import cn.wizzer.app.crown.modules.models.enums.MatchStageEnum;
import cn.wizzer.app.crown.modules.services.CrownMatchService;
import cn.wizzer.app.sys.modules.services.SysParamService;
import cn.wizzer.app.web.commons.filter.ApiTokenFilter;
import cn.wizzer.framework.util.Result;
import cn.wizzer.framework.page.Pagination;
import cn.wizzer.framework.util.param.ParamVerify;
import com.alibaba.dubbo.config.annotation.Reference;
import org.nutz.integration.jedis.RedisService;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.*;

import java.util.*;


/**
 * 皇冠赛事Controller
 *
 * @author
 */
@At("/api/match/hg")
@IocBean
@Filters({@By(type = ApiTokenFilter.class)})
public class ApiCrownMatchController {

    @Inject
    private RedisService redisService;

    @Reference
    @Inject
    private CrownMatchService matchService;

    @Reference
    @Inject
    private SysParamService sysParamService;


    /**
     * @return
     */
    @At("/hotBets")
    @Ok("json")
    @Filters(@By(type = ApiTokenFilter.class))
    public Result hotBets(@ParamVerify(required = true) String timezone) {
        return Result.success(matchService.hotBets(timezone));
    }


    /**
     * 联赛列表
     *
     * @return Result
     */
    @At("/leagueList")
    @Ok("json")
    @Filters(@By(type = ApiTokenFilter.class))
    public Result leagueList(@ParamVerify(required = true, name = "stage") MatchStageEnum stage,
                             @ParamVerify(required = true, name = "timezone") String timezone,
                             @ParamVerify(required = true) int pageNo,
                             @ParamVerify(required = true) int pageSize) {
        return Result.success(matchService.leagueList(stage, timezone, pageNo, pageSize));
    }


    /**
     * 查询赛事列表
     *
     * @return Result
     */
    @At("/matchList")
    @Ok("json")
    @Filters(@By(type = ApiTokenFilter.class))
    public Result matchList(@Param("stage") MatchStageEnum stage,
                            @Param("leagues") String[] leagues,
                            @ParamVerify(required = true) String timezone,
                            @ParamVerify(required = true) int pageNo,
                            @ParamVerify(required = true) int pageSize
    ) {
        List<String> leagueList = leagues != null ? new ArrayList<>(Arrays.asList(leagues)) : null;
        return Result.success(matchService.matchList(stage, leagueList, timezone, pageNo, pageSize));
    }


    /**
     * 比赛数量统计
     *
     * @return Result
     */
    @At("/matchCount")
    @Ok("json")
    @Filters(@By(type = ApiTokenFilter.class))
    public Result matchCount(@ParamVerify(required = true) String timezone) {
        return Result.success(matchService.matchCount(timezone));
    }


    /**
     * 根据比赛ID 查询所有玩法
     *
     * @param id 比赛ID
     * @return Result
     */
    @At("/allBets")
    @Ok("json:full")
    @Filters(@By(type = ApiTokenFilter.class))
    public Result allBets(@ParamVerify(required = true) String id, @Param("betType") BetsEnum betType) {
        return Result.success(matchService.composeMatch(betType, id));
    }


    /**
     * 赛果列表
     *
     * @param start    开始时间
     * @param end      结束时间
     * @param pageNo   页码
     * @param pageSize 页面容量
     * @return Result
     */
    @At("/resultList")
    @Ok("json")
    @Filters(@By(type = ApiTokenFilter.class))
    public Result resultList(@Param("timezone") String timezone,
                             @Param("start") Long start,
                             @Param("end") Long end,
                             @ParamVerify(required = true) int pageNo,
                             @ParamVerify(required = true) int pageSize) {
        Pagination pagination = matchService.resultList(timezone, start, end, pageNo, pageSize);
        return Result.success(pagination);
    }


    /**
     * 单条赛果查询
     *
     * @param id
     * @return
     */
    @At("/result")
    @Ok("json")
    @Filters(@By(type = ApiTokenFilter.class))
    public Result result(@ParamVerify(required = true) String id) {
        return Result.success(matchService.result(id));
    }


}





